/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agenda.client.view;

import javax.swing.JOptionPane;
import com.agenda.PrincipalCliente;
import com.agenda.client.ClienteServidor;
import com.agenda.client.requisicoes.LiberarEmoticonRequisicao;
import com.agenda.model.RespostaRequisicao;

/**
 *
 * @author Murilo
 */
public class CaracteresView extends javax.swing.JDialog {

	/**
	 * Creates new form CaracteresView
	 */
	public CaracteresView(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of
	 * this method is always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		apaixonadoButton = new javax.swing.JButton();
		chateadoButton = new javax.swing.JButton();
		raivaButton = new javax.swing.JButton();
		sorriso_grandeButton = new javax.swing.JButton();
		cancelarButton = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		getContentPane().setLayout(new java.awt.FlowLayout());

		apaixonadoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/agenda/client/view/imagens/apaixonado.jpg"))); // NOI18N
		apaixonadoButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				apaixonadoButtonActionPerformed(evt);
			}
		});
		getContentPane().add(apaixonadoButton);

		chateadoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/agenda/client/view/imagens/chateado.jpg"))); // NOI18N
		chateadoButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				chateadoButtonActionPerformed(evt);
			}
		});
		getContentPane().add(chateadoButton);

		raivaButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/agenda/client/view/imagens/raiva.jpg"))); // NOI18N
		raivaButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				raivaButtonActionPerformed(evt);
			}
		});
		getContentPane().add(raivaButton);

		sorriso_grandeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/agenda/client/view/imagens/sorriso_grande.jpg"))); // NOI18N
		sorriso_grandeButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				sorriso_grandeButtonActionPerformed(evt);
			}
		});
		getContentPane().add(sorriso_grandeButton);

		cancelarButton.setText("Cancelar");
		cancelarButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cancelarButtonActionPerformed(evt);
			}
		});
		getContentPane().add(cancelarButton);

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void chateadoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chateadoButtonActionPerformed
		charEscolhido = "chateado.jpg";
		fechar();
	}//GEN-LAST:event_chateadoButtonActionPerformed

	private void cancelarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarButtonActionPerformed
		fechar();
	}//GEN-LAST:event_cancelarButtonActionPerformed

	private void apaixonadoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_apaixonadoButtonActionPerformed
		charEscolhido = "apaixonado.jpg";
		fechar();
	}//GEN-LAST:event_apaixonadoButtonActionPerformed

	private void raivaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_raivaButtonActionPerformed
		charEscolhido = "raiva.jpg";
		fechar();
	}//GEN-LAST:event_raivaButtonActionPerformed

	private void sorriso_grandeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sorriso_grandeButtonActionPerformed
		charEscolhido = "sorriso_grande.jpg";
		fechar();
	}//GEN-LAST:event_sorriso_grandeButtonActionPerformed

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		/*
		 * Set the Nimbus look and feel
		 */
		//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. For details see
		 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(CaracteresView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(CaracteresView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(CaracteresView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(CaracteresView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		//</editor-fold>

		/*
		 * Create and display the dialog
		 */
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				CaracteresView dialog = new CaracteresView(new javax.swing.JFrame(), true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {

					@Override
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton apaixonadoButton;
	private javax.swing.JButton cancelarButton;
	private javax.swing.JButton chateadoButton;
	private javax.swing.JButton raivaButton;
	private javax.swing.JButton sorriso_grandeButton;

	// End of variables declaration//GEN-END:variables

	private String charEscolhido = null;

	public String getCharEscolhido() {

		return charEscolhido;
	}

	public void fechar() {

		try {
			RespostaRequisicao resposta = ClienteServidor.getINSTANCIA().enviarInformacao(
				new LiberarEmoticonRequisicao(PrincipalCliente.getUsuarioLogado()));

			if (resposta.isErro()) {
				JOptionPane.showMessageDialog(this, resposta.getMsg());
				return;
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ClienteServidor.getINSTANCIA().liberarComunicacao();
		}

		setVisible(false);
	}
}
